/**
 *@Author mengjun
 *@date 2019/10/914:43
 *@Version 1.0
 */

var user = {

    init:function(){
        // TODO  检测用户是否已登录，若已登录，调用goIndex方法；
    },
    login: function (data) {
        $.ajax({
            url: BASE.API + "/sysUser/login",
            type: "POST",
            contentType: "application/json",
            data: JSON.stringify(data),
            dataType: "json",
            xhrFields: {
                withCredentials: true
            },
            beforeSend: function () {
                var index = layer.load(1, {
                    shade: [0.1, '#fff'] //0.1透明度的白色背景
                });
            },
            success: function (data) {
                var msg = data.message;
                if (data.status != "200") {
                    // TODO 上面的status 改成boolean
                    TOOLS.WARN(msg);
                    return false;
                }
                TOOLS.SUCCESS_Hook(msg, user.goIndex);
                layer.load(0, {shade: false});
            },
            error: function (data) {
                console.log(data);
                TOOLS.ERROR();
            }
        })
        return false;
    },

    loginOut: function () {
        // TODO
    },
    goIndex: function () {
        window.location.href = "/Erms/Module/Index/Index.html";
    }
}